from datetime import date, datetime
from tkinter import Button, END, Tk, Menu, StringVar, Label, Text, _tkinter, LEFT, RIGHT, BOTH, X, Y

class EntryGUI(object):
    def __init__(self):
        self.todayStr = date.today().__str__()
        self.nowStr = datetime.today().strftime('%H:%M')
        
        self.root = Tk()
        self.root.title('TT Reminder for ' + self.todayStr + ' at '  + self.nowStr)
        try:
            self.root.iconbitmap(default='ttlogger.ico')
        except _tkinter.TclError:
            pass
        
        # create a top level menu
        self.menubar = Menu(self.root)
        
        self.filemenu = Menu(self.menubar, tearoff=0)
        self.filemenu.add_command(label="Properties")   
        self.filemenu.add_command(label="Exit", command=self.root.quit)
        
        self.menubar.add_cascade(label="File", menu=self.filemenu)
        #self.root.config(menu=self.menubar)
        
        self.labelText = StringVar()
        self.resetLabelText()
        self.w = Label(self.root, textvariable=self.labelText)
        self.w.pack(side='top', fill='x')
        
        self.t = Text(self.root);
        self.t.bind("<Key>", self.onKeyPressed)
        self.t.pack(side='top', fill=BOTH, expand=1)
        
        self.b = Button(self.root, text="OK", command=self.onOkPressed);
        self.b.pack(side='top', fill='x')
        
        self.root.mainloop()

    def onOkPressed(self):
        file = open(self.todayStr + '.txt', 'a')
        file.write(self.nowStr + ': ' + self.t.get(1.0, END))
        file.close()
        self.root.quit()
    
    def onKeyPressed(self, event):
        self.labelText.set("What you have been doing lately? " + str(len(self.t.get(1.0, END))) + " chars so far")
    
    def resetLabelText(self):
        self.labelText.set("What you have been doing lately? 0 chars so far")
        
if __name__ == "__main__":
    EntryGUI()